package com.hursing.tractor;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public final class GameView extends View {
	
	public interface GameViewDelegate {
		void onDraw(Canvas canvas);
		void onSizeChanged(int w, int h);
		void onTouchDown(int x, int y);
	}
	
	private GameViewDelegate mDelegate;
	public void setDelegate(GameViewDelegate gameViewDelegate) {
		mDelegate = gameViewDelegate;
	}
		
	public GameView(Context context, AttributeSet set) {
		super(context, set);		
	}
	
	@Override
	public void onDraw (Canvas canvas) {
		mDelegate.onDraw(canvas);
	}
	
	@Override
	protected void onSizeChanged (int w, int h, int oldw, int oldh) {
		mDelegate.onSizeChanged(w, h);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
			int x = (int) event.getX();
			int y = (int) event.getY();
			mDelegate.onTouchDown(x, y);
		}
		return true;
	}
}
